﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Negocios;
using System.Collections;
namespace UI
{
    public partial class CadDepartamento : Form
    {
        public CadDepartamento()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        { 
            Departamento dep = new Departamento();
            ArrayList arrLocal = new ArrayList();
            for (int x = 0; x < listBox1.Items.Count; x++) {
                arrLocal.Add((String)listBox1.Items[x]); 
            }
            if (dep.Cadastrar(new Departamento(txtDep.Text, txtChefe.Text, arrLocal)))
                MessageBox.Show("Cadastrado");
            else
            {
                MessageBox.Show("Não Cadastrado");
            }
           
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (txtlocal.Text != "")
            {
                if (listBox1.Items.Count > 0)
                {
                    int qtd_list = listBox1.Items.Count;
                    for (int x = 0; x < qtd_list; x++)
                    {
                        if (txtlocal.Text == (String)listBox1.Items[x])
                        {
                            MessageBox.Show("já inserido");
                            break;
                        }
                        else
                        {
                            if ((x + 1) == listBox1.Items.Count)
                                listBox1.Items.Add(txtlocal.Text);
                        }
                    }
                    txtlocal.Text = "";
                    txtlocal.Focus();
                }
                else
                {
                    listBox1.Items.Add(txtlocal.Text);
                    txtlocal.Text = "";
                    txtlocal.Focus();
                }
            }else{
                MessageBox.Show("Em branco");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int ind_select = listBox1.SelectedIndex;
            if (ind_select >= 0)
                listBox1.Items.RemoveAt(ind_select);
            else
                MessageBox.Show("Nenhum Item Selecionado");

           
        }

        private void txtlocal_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
